package com.leetcode.merci.lc257;



import com.leetcode.merci.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by bowen on 2017/7/23.
 */
public class Solution {
    public List<String> binaryTreePaths(TreeNode root) {
        List<String> paths = new ArrayList<>();
        List<TreeNode> list=new ArrayList<>();
        if(root==null){
            return paths;
        }
        else{
            list.add(root);
            return makePaths(root,list,paths);
        }

    }
    public List<String> makePaths(TreeNode root,List<TreeNode> list,List<String> paths){
            TreeNode t;
        if(root.left==null && root.right==null){
            String result = "";
            for(TreeNode node:list){
                result+=node.val+"->";
            }
            result=result.substring(0,result.length()-2);
            paths.add(result);
            list.remove(root);
            return paths;
        }
        if(root.left!=null){
            t=root.left;
            list.add(t);
            paths = makePaths(t,list,paths);
            list.remove(t);
        }
        if(root.right!=null){
            t=root.right;
            list.add(t);
            paths = makePaths(t,list,paths);
            list.remove(t);
        }
        return paths;
    }

}
